var webserver = function(config){
	config = config || {};
	//Lets require/import the HTTP module
	var http = require('http');
	//Lets define a port we want to listen to
	var PORT = config.port || 8080; 

	return {
		maps:{},
		connect: function(){
			var oThis = this;
			//We need a function which handles requests and send response
			function handleRequest(request, response){
				var cback = oThis.maps[request.url];
				if(cback)
					response.end(cback(request));
				else
					response.end(request.url + " not found on <br/>" + JSON.stringify(oThis.maps));
			}
			//Create a server
			var server = http.createServer(handleRequest);
			//Lets start our server
			server.listen(PORT, function(){
				//Callback triggered when server is successfully listening. Hurray!
				console.log("Server listening on: http://localhost:%s", PORT);
			});
			return this;
		},
		map: function(url, callback){
			if(url[0] != '/')
				url = "/" + url;	
			this.maps[url] = callback;
			return this;
		}
	}
}

if(typeof(module) !== "undefined")
	module.exports = webserver;